package com.example.settings.service.impl;

import com.example.settings.dao.DicTypeDao;
import com.example.settings.dao.DicValueDao;
import com.example.settings.domain.DicType;
import com.example.settings.domain.DicValue;
import com.example.settings.service.DicService;
import com.example.utils.SqlSessionUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DicServiceImpl implements DicService {

    private DicTypeDao dicTypeDao = SqlSessionUtil.getSqlSession().getMapper(DicTypeDao.class);
    private DicValueDao dicValueDao =SqlSessionUtil.getSqlSession().getMapper(DicValueDao.class);

    public Map<String, List<DicValue>> getDic() {
        Map<String,List<DicValue>> map = new HashMap<String, List<DicValue>>();
        //获取数据字典类型
        List<DicType> codeList = dicTypeDao.getCodeList();

        for (DicType dicType:codeList) {
            //从数据字典类型对象获取code类型
            String code= dicType.getCode() ;
            System.out.println(code);

            //根据数据字典类型----获取数据字典值
            List<DicValue> dicValueList = dicValueDao.getValue(code);
            map.put(code,dicValueList);
            System.out.println(dicValueList);
        }

        //打包成map返回
        return map;
    }
}
